// -----------------------------------------------------------------------
// <copyright file="NodeWorkflowRollEN.cs" company="VDC-IT" author="LTDUC">
//      Copyright (c) VDC-IT. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

using System.Collections;
using System.Collections.Generic;

namespace VDC.VONE.ENTITIES
{
    using System;
    using System.Data.SqlClient;
    using Microsoft.ApplicationBlocks.Data;
    using VDC.COMMON;
    
    /// <summary>
    /// Class NodeWorkflowRoll
    /// </summary>
    public class NodeWorkflowRollEN : EntityEN
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="NodeWorkflowRollEN" /> class
        /// </summary>
        public NodeWorkflowRollEN()
        {
            this.NodeWorkflowRollId = 0;
            this.NodeWorkflowId = 0;
            this.DepartmentId = 0;
            this.RoleName = string.Empty;
            this.ToCc = false;
        }
        
        /// <summary>
        /// Gets or sets NodeWorkflowRollId
        /// </summary>
        public int NodeWorkflowRollId { get; set; }

        /// <summary>
        /// Gets or sets NodeWorkflowId
        /// </summary>
        public int NodeWorkflowId { get; set; }

        /// <summary>
        /// Gets or sets DepartmentId
        /// </summary>
        public int DepartmentId { get; set; }

        /// <summary>
        /// Gets or sets RoleName
        /// </summary>
        public string RoleName { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether ToCc
        /// </summary>
        public bool ToCc { get; set; }

        /// <summary>
        /// Gets Department
        /// </summary>
        public DepartmentEN Department
        {
            get
            {
                try
                {
                    DepartmentEN department = null;
                    SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneDepartmentGetById, this.DepartmentId);

                    while (reader.Read())
                    {
                        department = new DepartmentEN();

                        if (!reader.IsDBNull(0))
                        {
                            department.DepartmentId = reader.GetInt32(0);
                        }

                        if (!reader.IsDBNull(1))
                        {
                            department.Code = reader.GetString(1);
                        }

                        if (!reader.IsDBNull(2))
                        {
                            department.Name = reader.GetString(2);
                        }

                        if (!reader.IsDBNull(3))
                        {
                            department.Parent = reader.GetInt32(3);
                        }

                        if (!reader.IsDBNull(4))
                        {
                            department.Order = reader.GetInt32(4);
                        }
                    }

                    reader.Close();
                    reader.Dispose();

                    return department;
                }
                catch (SqlException ex)
                {
                    throw new Exception(ex.ToString());
                }
            }
        }

        /// <summary>
        /// Gets NodeWorkflow
        /// </summary>
        public NodeWorkflowEN NodeWorkflow
        {
            get
            {
                try
                {
                    NodeWorkflowEN nodeWorkflow = null;
                    var reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneNodeWorkflowGetByWorkflowId, this.NodeWorkflowId);
                    while (reader.Read())
                    {
                        nodeWorkflow = new NodeWorkflowEN();
                        if (!reader.IsDBNull(0))
                        {
                            nodeWorkflow.NodeWorkflowId = reader.GetInt32(0);
                        }

                        if (!reader.IsDBNull(1))
                        {
                            nodeWorkflow.WorkflowId = reader.GetInt32(1);
                        }

                        if (!reader.IsDBNull(2))
                        {
                            nodeWorkflow.NodeId = reader.GetInt32(2);
                        }

                        if (!reader.IsDBNull(3))
                        {
                            nodeWorkflow.ConditionsId = reader.GetInt32(3);
                        }

                        if (!reader.IsDBNull(4))
                        {
                            nodeWorkflow.NextNodeId = reader.GetInt32(4);
                        }

                        if (!reader.IsDBNull(5))
                        {
                            nodeWorkflow.ProfileTypeProgressId = reader.GetInt32(5);
                        }

                        if (!reader.IsDBNull(6))
                        {
                            nodeWorkflow.ProfileStatusId = reader.GetInt32(6);
                        }

                        if (!reader.IsDBNull(7))
                        {
                            nodeWorkflow.Orders = reader.GetInt32(7);
                        }

                        if (!reader.IsDBNull(8))
                        {
                            nodeWorkflow.Send = reader.GetString(8);
                        }

                        if (!reader.IsDBNull(9))
                        {
                            nodeWorkflow.PrintReceipt = reader.GetBoolean(9);
                        }

                        if (!reader.IsDBNull(10))
                        {
                            nodeWorkflow.PrintVotehandover = reader.GetBoolean(10);
                        }
                    }

                    reader.Close();
                    reader.Dispose();
                    return nodeWorkflow;
                }
                catch (SqlException ex)
                {
                    throw new Exception(ex.ToString());
                }
            }
        }

        /// <summary>
        /// Gets the node wf role defaults.
        /// </summary>
        /// <value>
        /// The node wf role defaults.
        /// </value>
        public IList<NodeWFRoleDefaultEN> NodeWfRoleDefaults
        {
            get
            {
                try
                {
                    IList<NodeWFRoleDefaultEN> nodeWfRoleDefaultEns = new List<NodeWFRoleDefaultEN>();
                    var reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneNodeWFRoleDefaultGetByNodeWorkflowRollId, this.NodeWorkflowRollId);
                    while (reader.Read())
                    {
                        NodeWFRoleDefaultEN nodeWfRoleDefaultEn = new NodeWFRoleDefaultEN();
                        if (!reader.IsDBNull(0))
                        {
                            nodeWfRoleDefaultEn.NodeWFRoleDefaultId = reader.GetInt32(0);
                        }

                        if (!reader.IsDBNull(1))
                        {
                            nodeWfRoleDefaultEn.NodeWorkflowRollId = reader.GetInt32(1);
                        }

                        if (!reader.IsDBNull(2))
                        {
                            nodeWfRoleDefaultEn.ProfileTypeId = reader.GetInt32(2);
                        }

                        nodeWfRoleDefaultEns.Add(nodeWfRoleDefaultEn);
                    }

                    reader.Close();
                    reader.Dispose();
                    return nodeWfRoleDefaultEns;
                }
                catch (SqlException ex)
                {
                    throw new Exception(ex.ToString());
                }
            }
        }
    }
}
